package org.example.service;

import jakarta.servlet.http.HttpServletRequest;
import org.example.dataobject.CommentDO;
import org.example.error.BusinessException;
import org.example.service.model.UserModel;
import org.example.service.model.invitation;

import java.net.http.HttpRequest;
import java.util.List;

/**
 * @author xietl
 * @date 2025/8/26  10:21
 * @description 帖子实体的实现接口
 */
public interface InvitationService {
    /**
     * 创建帖子
     * @param post
     * @return
     */
    Boolean createInvitation(invitation post) throws BusinessException;

    /**
     * 删除帖子
     * @param postid
     * @param httpServletRequest
     * @return
     */
    int deleteInvittion(int postid,HttpServletRequest httpServletRequest) throws BusinessException;


    /**
     * 修改帖子内容
     * @param post
     * @return
     */
    int updateInvitation(invitation post);



    List<invitation> queryInvitationsBySort(String sortType) throws BusinessException;

    /**
     * 根据作者名字查询帖子
     * @param username
     * @return
     */
    List<invitation> queryInvtatonsByusername(String username);

    /**
     * 根据分类进行筛选帖子
     * @param categoryname
     * @return
     */
    List<invitation> queryInvtationsBycategoryname(String categoryname);

    /**
     * 根据标题名称进行模糊筛选帖子
     * @param titleWord
     * @return
     */
    List<invitation> queryInvtationsBytitleWord(String titleWord);

    /**
     * 根据帖子id查询帖子详情
     * @param postid
     * @return
     */
    invitation queryInvitationDetail(int postid) throws BusinessException;



    /**
     * 使用乐观锁的点赞方法，解决多用户并发点赞问题
     * @param postid 帖子ID
     * @param request HTTP请求
     * @return 更新行数
     * @throws BusinessException 业务异常
     */
    int likeInvitationOptimistic(int postid, HttpServletRequest request) throws BusinessException;

    /**
     * 使用乐观锁的取消点赞方法
     * @param postid 帖子ID
     * @param request HTTP请求
     * @return 更新行数
     * @throws BusinessException 业务异常
     */
    int unlikeInvitationOptimistic(int postid, HttpServletRequest request) throws BusinessException;

    /**
     * 添加评论
     * @param postid 帖子ID
     * @param commentContent 评论内容
     * @param request HTTP请求
     * @return 评论ID
     * @throws BusinessException 业务异常
     */
    CommentDO addComment(int postid, String commentContent, HttpServletRequest request) throws BusinessException;

    List<CommentDO> getCommentsByPostId(int postId) throws BusinessException;
    int deleteComment(int commentId, HttpServletRequest request) throws BusinessException;

     /**
      * 主动失效指定帖子的评论缓存
      * @param postId 帖子ID
      */
     void invalidateCommentCache(int postId);

//    int likeInvitation(int postid, HttpServletRequest request) throws BusinessException;
//    int unlikeInvitation(int postid, HttpServletRequest request) throws BusinessException;
}
